#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<string>
using namespace std;
void test(const string& s1)
{
	string::const_iterator ptr1 = s1.cbegin();
	string::const_reverse_iterator ptr2 = s1.crbegin();
	while (ptr2 != s1.crend())
	{
		cout <<*ptr2 << " ";
		ptr2++;
	}
	cout << endl;
	while (ptr1 != s1.cend())
	{
		cout << *ptr1 << " ";
		ptr1++;

	}
	cout << endl;
}
void test2()
{
	string s1("hello world");
	string::iterator ptr3 = s1.begin();
	while (ptr3 != s1.end())
	{
		cout << *ptr3 << " ";
		ptr3++;
	}
	cout << endl;
	string::reverse_iterator ptr1 = s1.rbegin();
	string::reverse_iterator ptr2 = s1.rend();
	while (ptr1 != ptr2)
	{
		cout << *ptr1 << " ";
		ptr1++;
	}
	cout << endl;


}
void test02()
{
	string s1 = "hello world";
	cout << s1.size() << endl << s1.length() << endl;
	cout << s1.max_size() << endl;
}
void test03()
{
	string s1;
	size_t old = s1.capacity();
	cout << s1.capacity() << endl;
	for (int i = 0; i < 100; i++)
	{
		s1.push_back('x');

		if (old != s1.capacity())
		{
			cout << s1.capacity() << endl;
			old = s1.capacity();

		}
	}
	s1.clear();
	cout << s1.size() << endl;
	cout << s1.capacity() << endl;
	cout << s1 << endl;
	string s2;
	
	if (s2.empty())
	{
		cout << "1" << endl;
	}
	else
	{
		cout << "0" << endl;
	}




}
void test04()
{

	string s4("dadadaddadadaddaffffffffffffffffffffffffffffffffffffffffffffffff");
	s4.reserve(5000);
	cout << s4.size() << endl;
	cout << s4.capacity() << endl;
	s4.reserve(3000);
	cout << s4.size() << endl;
	cout << s4.capacity() << endl;
	s4.shrink_to_fit();
	cout << s4.size() << endl;
	cout << s4.capacity() << endl;

}
void test05()
{
	string s5 = "dddddddddddddd";
	for (int i = 0; i < s5.size(); i++)
	{
		cout << s5[i] << " ";
	}
	cout << endl;
	for (int i = 0; i < s5.size(); i++)
	{
		cout << s5.at(i) << " ";
	}
	cout << s5.front() << endl;
	cout << s5.back() << endl;

	cout << endl;
}
void test06()
{
	string s6 = "ddddddddd";
	cout << s6 << endl;
	s6 += "xxxxxxxx";
	cout << s6 << endl;
	s6 += 'a';
	cout << s6 << endl;
	string s7 = "wwwwwwwww";
	cout << s6 << endl;
	s6 += s7;
	cout << s6 << endl;
	s6.append("hhhhhhhh");
	cout << s6 << endl;
	s6.append(s7.begin(), s7.end());
	cout << s6 << endl;
	cout << s6.size() << endl << s6.capacity() << endl;
	//s6.resize(10);
	s6.reserve(10);
	cout << s6.size() << endl << s6.capacity() << endl;
	cout << s6 << endl;
	s6.erase(20);
	cout << s6 << endl;
	cout << s6.size() << endl << s6.capacity() << endl;
	s6.erase(s6.begin());
	cout << s6 << endl;
	s6.erase(s6.begin() + 3, s6.begin() + 6);
	cout << s6 << endl;

}
void test07()
{
	string s7 = "Դ.cpp";
	FILE* fp = fopen(s7.c_str(), "r");
	char  ch = fgetc(fp);
	while (ch != EOF)
	{
		cout << ch;
		ch = fgetc(fp);
	}

}
void test08()
{

	string s6 = "ddddddddd";
	cout << s6 << endl;
	string s7("ssssssss");

	cout << s6 << endl;
	s6.insert(s6.begin(), s7.begin(), s7.end());

	cout << s6 << endl;
	s6.insert(3, "aaaaaaaaaa");

	cout << s6 << endl;
	s6.insert(0, 1, '%');

	cout << s6 << endl;
	s6.insert(s6.begin(), 'a');

	cout << s6 << endl;
}
void test09()
{
	string str = "hello world";
	str.replace(5, 1, "%%%");
	cout << str << endl;



}
void test10()
{

	string s1 = "hello world";
	cout << s1.size() << endl << s1.capacity() << endl;
	s1.resize(5);
	cout << s1 << endl;
	s1.resize(200, '!');
	s1.resize(10);



}
int main()
{
	string s1("hello world");
	//test(s1);
	//test2();
	//test03();
	//test04();
	//test05();
	test06();
	//test07();
	//test08();
	//test09();
	//test10();
	return 0;
}